<template>
	<div class="content">
		<h2><i class="iconfont icon-jinbi"></i>管理员列表</h2>
		<div class="content-wrap">
			<div class="content-wrap__add-admin">
				<router-link to="/admin/permission_add">
					<el-button icon="el-icon-edit" type="primary">添加管理员</el-button>
				</router-link>
			</div>
			<!--商品展示表格-->
			<div class="content-table" v-loading="loading" >
				<el-table :data="data" strip height="550" >
					<el-table-column label="管理员名称" align="center">
						<template slot-scope="scope" >
							<span>{{scope.row.user_name}}</span>
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="250">
						<template slot-scope="scope" size="small">
							<el-button 
								size="small"
								@click="assignAdmin(scope.row.user_id)"
								 type="primary" 
								 >
								 权限管理
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<el-pagination 
				@current-change="handleCurrentChange"
				background 
				layout="total, prev, pager, next, jumper"
				:total="totalNum" 
				class="fr"
				>
			</el-pagination>
		</div>
		<s-permission-assign :id="adminId" v-if="showModel"></s-permission-assign>
	</div>
</template>

<script>
	import permissionAssign from "./children/permission_assign.vue"
	export default {
		created() {
			this.fetchCompnayList();
		},
		components: {
			"s-permission-assign": permissionAssign
		},
		data() {
			return {
				params: {
					page: 1,
					rows: 10,
					start_time: "",
					end_time: "",
					state: '',			//审核状态
				},
				data: null,		
				showModel: false,
				adminId: "",				//
				loading: true,				//加载小圈圈
				totalNum: 0					//返回数据总数，用于分页那里显示
			}
		},
		methods: {
			//翻页
			handleCurrentChange(pages) {
				this.params.page = pages;
				this.fetchCompnayList();
			},
			//获取管理员列表
			fetchCompnayList() {
				this.loading = true;
				var url = `${this.url}/auth/user_get_all_manager.action`;
				var params = this.params;
				this.$http.get(url,{ params }).then((res)=> {
					this.totalNum = res.data.result.total;
					this.loading = false;
					this.data = res.data.result.rows;
				});
			},
			assignAdmin(id) {
				this.adminId = id;
				this.showModel = true;
			}

		}

	}
</script>

<style scoped lang="scss">
	.content-wrap__add-admin {
		margin-bottom: 20px;
		float: right;
	}
</style>